package com.newdjk.newdoctor.net;

import android.content.Context;
import android.content.Intent;

import com.newdjk.newdoctor.MainActivity;
import com.newdjk.newdoctor.MyApplication;
import com.newdjk.newdoctor.dialog.LoadDialog;
import com.newdjk.newdoctor.ui.LoginActivity;
import com.newdjk.newdoctor.ui.SplashActivity;
import com.newdjk.newdoctor.utils.Contants;
import com.newdjk.newdoctor.utils.SpUtils;
import com.newdjk.newdoctor.utils.ToastUtil;
import com.newdjk.okhttp.BaseObserver;
import com.newdjk.okhttp.entity.BaseEntity;

public abstract class BaseComPleteObserver<T> extends BaseObserver<T> {
    public BaseComPleteObserver(Context cxt) {
        super(cxt);
    }

    public BaseComPleteObserver(Context cxt, boolean isshowDialog) {
        super(cxt, isshowDialog);
    }

    public BaseComPleteObserver() {
        super();
    }

    @Override
    protected void onCodeError(BaseEntity t) throws Exception {
        LoadDialog.clear();
        ToastUtil.setToast(t.getMessage() + "");
    }


    @Override
    protected void onFailure(Throwable e, String erroressage, boolean isNetWorkError) throws Exception {

        if (erroressage.equals("未授权的请求")) {
            ToastUtil.setLongToast("登录失效，请重新登录");
            SpUtils.put(Contants.Id, 0);
            SpUtils.put(Contants.toLogin, "0");
            SpUtils.put(Contants.logoOut, true);
            SpUtils.put(Contants.LoginJson, "");
            Intent intent = new Intent(MyApplication.getContext(), LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            MyApplication.getContext().startActivity(intent);

        }else {
            ToastUtil.setToast(erroressage + "");
        }


    }
}
